<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fnx" uri="http://java.sun.com/jsp/jstl/functionsx" %>
<%@ taglib prefix="s" uri="http://www.springframework.org/tags" %>
<%@ taglib prefix="f" uri="http://www.sctv.com/tags/form" %>
<%@ taglib prefix="shiro" uri="http://shiro.apache.org/tags" %>
<%@ taglib prefix="tags" tagdir="/WEB-INF/tags" %>
<!DOCTYPE html>
<html>
<head>
    <jsp:include page="/WEB-INF/views/head.jsp"/>
    <script type="text/javascript">
      $(function () {
        $("#validForm").validate();
        $("input[name='name']").focus();
      });

      function  checkData(){
        var address=$("#address").val();
        var audioUrl=$("#audioUrl").val();
        var smallImage=$("#smallImage").val();
        if(address=="" && audioUrl==""){
          alert("请填写播放地址、音频地址,其中一个！");
          return false;
        }
        if(address!="" && audioUrl!=""){
          alert("播放地址、音频地址，只能填写其中一个");
          return false;
        }
        if(audioUrl!="" && address=="" && smallImage==""){
          alert("填写音频地址后，需要上传音频封面图！");
          return false;
        }
      }

      function confirmDelete() {
        return confirm("<s:message code='confirmDelete'/>");
      }
    </script>
</head>
<body class="skin-blue content-body">
<jsp:include page="/WEB-INF/views/commons/show_message.jsp"/>
<div class="content-header">
    <h1><s:message code="sinatv"/> - <s:message code="${oprt=='edit' ? 'edit' : 'create'}"/></h1>
</div>

<div class="content">
    <div class="box box-primary">
        <form class="form-horizontal" id="validForm" action="${oprt=='edit' ? 'update' : 'save'}.do" method="post" onsubmit="return checkData();">
            <tags:search_params/>
            <f:hidden name="oid" value="${bean.id}"/>
            <f:hidden name="position" value="${position}"/>
            <input type="hidden" id="redirect" name="redirect" value="edit"/>
            <div class="box-header with-border">
                <div class="btn-toolbar">
                    <div class="btn-group">
                        <shiro:hasPermission name="core:sensitive_word:create">
                            <button class="btn btn-default" type="button"
                                    onclick="location.href='create.do?${searchstring}';"<c:if
                                    test="${oprt=='create'}"> disabled="disabled"</c:if>><s:message
                                    code="create"/></button>
                        </shiro:hasPermission>
                    </div>
                    <div class="btn-group">
                        <shiro:hasPermission name="core:sensitive_word:delete">
                            <button class="btn btn-default" type="button"
                                    onclick="if(confirmDelete()){location.href='delete.do?ids=${bean.id}&${searchstring}';}"
                                    <c:if test="${oprt=='create'}"> disabled="disabled"</c:if>><s:message
                                    code="delete"/></button>
                        </shiro:hasPermission>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-default" type="button"
                                onclick="location.href='edit.do?id=${side.prev.id}&position=${position-1}&${searchstring}';"
                                <c:if test="${empty side.prev}"> disabled="disabled"</c:if>><s:message
                                code="prev"/></button>
                        <button class="btn btn-default" type="button"
                                onclick="location.href='edit.do?id=${side.next.id}&position=${position+1}&${searchstring}';"
                                <c:if test="${empty side.next}"> disabled="disabled"</c:if>><s:message
                                code="next"/></button>
                    </div>
                    <div class="btn-group">
                        <button class="btn btn-default" type="button"
                                onclick="location.href='list.do?${searchstring}';"><s:message code="return"/></button>
                    </div>
                </div>
            </div>
            <span style="color: red;margin-left: 169px;">注意：播放地址、音频地址只填写其中一个，填写音频地址，必须上传音频图片</span>
            <div class="box-body">
                <div class="row">

                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><em class="required">*</em><s:message code="sinatv"/></label>
                            <div class="col-sm-8">
                                <f:text class="form-control required" name="name"
                                        value="${oprt=='edit' ? (bean.name) : ''}" maxlength="100"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-4 control-label"><s:message
                                    code="broadcast.address"/></label>
                            <div class="col-sm-8">
                                <f:text class="form-control" id="address" name="address"
                                        value="${oprt=='edit' ? (bean.address) : ''}" maxlength="100"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">logo图片:</label>
                            <div class="col-sm-10">
                                <script>
                                  function fn_logoImage(src) {
                                    Cms.scaleImg("img_logoImage", 200, 100, src);
                                  };
                                </script>
                                <div style="display:table;width:100%;">
                                    <div style="display:table-cell;vertical-align:middle;">
                                        <div class="input-group">
                                            <span class="input-group-addon">地址</span>
                                            <input type="text" id="logoImage" name="logoImg"
                                                   value="${bean.logoImg}"
                                                   onchange="fn_logoImage(this.value);" class="form-control">
                                        </div>
                                        <div class="form-inline" style="margin-top:3px;">
                                            <button class="btn btn-default" type="button" id="logoImageButton">选择
                                            </button>
                                            <object id="SWFUpload_0" type="application/x-shockwave-flash"
                                                    data="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304"
                                                    width="54" height="34" class="swfupload">
                                                <param name="wmode" value="transparent">
                                                <param name="movie"
                                                       value="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304">
                                                <param name="quality" value="high">
                                                <param name="allowScriptAccess" value="always">
                                                <param name="flashvars"
                                                       value="movieName=SWFUpload_0&amp;uploadURL=%2Fcmscp%2Fcore%2Fupload_image.do%3Bjsessionid%3DB7EED2164EABD024D9BFE3361803971D%3F_site%3D&amp;useQueryString=false&amp;requeueOnError=false&amp;httpSuccess=&amp;assumeSuccessTimeout=0&amp;params=&amp;filePostName=file&amp;fileTypes=*.*&amp;fileTypesDescription=Images&amp;fileSizeLimit=0&amp;fileUploadLimit=0&amp;fileQueueLimit=0&amp;debugEnabled=false&amp;buttonImageURL=&amp;buttonWidth=54&amp;buttonHeight=34&amp;buttonText=&amp;buttonTextTopPadding=0&amp;buttonTextLeftPadding=0&amp;buttonTextStyle=color%3A%20%23000000%3B%20font-size%3A%2016pt%3B&amp;buttonAction=-100&amp;buttonDisabled=false&amp;buttonCursor=-2">
                                            </object>
                                            <button class="btn btn-default" type="button">上传</button>
                                            <div style="display: none">
                                                <button class="btn btn-default" type="button" id="logoImageSwfCancel"
                                                        onclick="logoImageSwfUpload.cancelQueue();" disabled="">取消
                                                </button>
                                            </div>

                                        </div>

                                        <input type="hidden" id="t_logoImage" value="false">
                                        <input type="hidden" id="tw_logoImage" value="116">
                                        <input type="hidden" id="th_logoImage" value="77">
                                    </div>
                                    <div style="width:200px;display:table-cell;vertical-align:middle;text-align:center;">
                                        <img id="img_logoImage" <c:if test="${empty bean.logoImg}">style="display:none;"</c:if>  src="${bean.logoImg}">
                                    </div>
                                </div>
                                <div id="logoImageSwfProgress"></div>
                                <script>
                                  var logoImageSwfUpload = Cms.swfUploadImage("logoImage", {
                                    jsessionid: "B7EED2164EABD024D9BFE3361803971D",
                                    file_size_limit: "0",
                                    file_types: "*.*"
                                  });
                                  $(function () {
                                    Cms.f7.uploads("logoImage", "logoImage", {
                                      settings: {"title": "选择附件"},
                                      callbacks: {
                                        "ok": function (src) {
                                          fn_logoImage(src);
                                        }
                                      }
                                    });
                                  });
                                </script>
                            </div>
                        </div>
                    </div>

                    <div class="col-sm-6">
                        <div class="form-group">
                            <label class="col-sm-4 control-label">音频地址</label>
                            <div class="col-sm-8">
                                <f:text class="form-control" id="audioUrl" name="audioUrl"
                                        value="${oprt=='edit' ? (bean.audioUrl) : ''}" maxlength="100"/>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-12">
                        <div class="form-group">
                            <label class="col-sm-2 control-label">音频图片:</label>
                            <div class="col-sm-10">
                                <script>
                                  function fn_smallImage(src) {
                                    Cms.scaleImg("img_smallImage", 200, 100, src);
                                  };
                                </script>
                                <div style="display:table;width:100%;">
                                    <div style="display:table-cell;vertical-align:middle;">
                                        <div class="input-group">
                                            <span class="input-group-addon">地址</span>
                                            <input type="text" id="smallImage" name="audioImg"
                                                   value="${bean.audioImg}"
                                                   onchange="fn_smallImage(this.value);" class="form-control">
                                        </div>
                                        <div class="form-inline" style="margin-top:3px;">
                                            <button class="btn btn-default" type="button" id="smallImageButton">选择
                                            </button>
                                            <object id="SWFUpload_1" type="application/x-shockwave-flash"
                                                    data="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304"
                                                    width="54" height="34" class="swfupload">
                                                <param name="wmode" value="transparent">
                                                <param name="movie"
                                                       value="/static/vendor/swfupload/swfupload.swf?preventswfcaching=1502702265304">
                                                <param name="quality" value="high">
                                                <param name="allowScriptAccess" value="always">
                                                <param name="flashvars"
                                                       value="movieName=SWFUpload_1&amp;uploadURL=%2Fcmscp%2Fcore%2Fupload_image.do%3Bjsessionid%3DB7EED2164EABD024D9BFE3361803971D%3F_site%3D&amp;useQueryString=false&amp;requeueOnError=false&amp;httpSuccess=&amp;assumeSuccessTimeout=0&amp;params=&amp;filePostName=file&amp;fileTypes=*.*&amp;fileTypesDescription=Images&amp;fileSizeLimit=0&amp;fileUploadLimit=0&amp;fileQueueLimit=0&amp;debugEnabled=false&amp;buttonImageURL=&amp;buttonWidth=54&amp;buttonHeight=34&amp;buttonText=&amp;buttonTextTopPadding=0&amp;buttonTextLeftPadding=0&amp;buttonTextStyle=color%3A%20%23000000%3B%20font-size%3A%2016pt%3B&amp;buttonAction=-100&amp;buttonDisabled=false&amp;buttonCursor=-2">
                                            </object>
                                            <button class="btn btn-default" type="button">上传</button>
                                            <div style="display: none">
                                                <button class="btn btn-default" type="button" id="smallImageSwfCancel"
                                                        onclick="smallImageSwfUpload.cancelQueue();" disabled="">取消
                                                </button>
                                            </div>

                                        </div>

                                        <input type="hidden" id="t_smallImage" value="false">
                                        <input type="hidden" id="tw_smallImage" value="116">
                                        <input type="hidden" id="th_smallImage" value="77">
                                    </div>
                                    <div style="width:200px;display:table-cell;vertical-align:middle;text-align:center;">
                                        <img id="img_smallImage" <c:if test="${empty bean.audioImg}">style="display:none;"</c:if>  src="${bean.audioImg}">
                                    </div>
                                </div>
                                <div id="smallImageSwfProgress"></div>
                                <script>
                                  var smallImageSwfUpload = Cms.swfUploadImage("smallImage", {
                                    jsessionid: "B7EED2164EABD024D9BFE3361803971D",
                                    file_size_limit: "0",
                                    file_types: "*.*"
                                  });
                                  $(function () {
                                    Cms.f7.uploads("smallImage", "smallImage", {
                                      settings: {"title": "选择附件"},
                                      callbacks: {
                                        "ok": function (src) {
                                          fn_smallImage(src);
                                        }
                                      }
                                    });
                                  });
                                </script>
                            </div>
                        </div>
                    </div>
                    <div class="col-sm-6">
                        <%--<f:text id="flash" name="flash" value="${bean.flash}" class="form-control required" maxlength="255"/>--%>
                        <label class="col-sm-4 control-label" style="width:233px"><em class="required"></em>上传节目单</label>
                        <%------------------------------------------------[ 测试 ]------------------------------------%>
                        <textarea id="filesTemplateArea" style="display:none;">
						      <div style="margin-top:5px;">
						      	<div style="display:table-cell;vertical-align:middle;width:9999px;">
							      	<div class="input-group">
							      		<span class="input-group-addon"><s:message code="fileUrl"/></span>
							      		<f:text class="form-control" id="files{0}" name="filesFile" value="{1}"
                                                maxlength="255"/>
							      	</div>
				              <script>
								      $(function () {
                                        Cms.f7.uploads("files{0}", "files{0}Name", {
                                          settings: {"title": "<s:message code="webFile.chooseUploads"/>"}
                                        });
                                      });
								      </script>
						      	</div>
						      </div>
						    </textarea>
                        <script type="text/javascript">
                          var fileRowIndex = 0;
                          var fileRowTemplate = $.format($("#filesTemplateArea").val());

                          function addFileRow(url, name, length, data) {
                            var programmes = data.programmes;
                            $('#filesContainer').html("");
                            $("<input type='hidden' name='programmes' value='"+programmes+"'/>").appendTo("#filesContainer");
                            $(fileRowTemplate(fileRowIndex++, url, name, length)).appendTo("#filesContainer");
                          }

                          function filesRemove(button) {
                            var toMove = $(button).parent().parent().parent();
                            toMove.remove();
                          }

                          function filesMoveUp(button) {
                            var toMove = $(button).parent().parent().parent();
                            toMove.prev().before(toMove);
                          }

                          function filesMoveDown(button) {
                            var toMove = $(button).parent().parent().parent();
                            toMove.next().after(toMove);
                          }
                        </script>
                        <div class="col-sm-8">
                            <span id="filesSwfButton"></span>
                            <button class="btn btn-default" type="button" onclick="filesSwfUpload.startUpload();"><s:message code="upload"/></button>
                        </div>
                        <div style="display: none">
                            <button class="btn btn-default" id="filesSwfCancel" type="button"
                                    onclick="filesSwfUpload.cancelQueue();" disabled><s:message code="cancel"/></button>
                            <%--<button class="btn btn-default" type="button" onclick="addFileRow('','','');"><s:message code='addRow'/></button>--%>
                        </div>
                        <div id="filesSwfProgress"></div>
                        <script type="text/javascript">
                            /*--------------------------[ 该方法上传节目单]----------------------------*/
                            var filesSwfUpload = Cms.swfUploadFileChannel("files", {
                              jsessionid: "<%=request.getSession().getId()%>",
                              file_size_limit: "${GLOBAL.upload.fileLimit}",
                              file_types: "${GLOBAL.upload.fileTypes}"
                            }, addFileRow);
                        </script>

                        <%------------------------------------------------[ 测试  Eed ]------------------------------------%>
                    </div>
                    <div class="col-sm-6">
                        <div class="form-group">
                            <div id="filesContainer" style="display: none"></div>
                        </div>
                    </div>
                </div>
            </div>
            <script type="text/javascript">
              function SetChannel() {
                var url = "";
                $("#filesContainer input[name='filesFile']").each(function () {
                  var u = $(this).val();
                  url += u + ',';
                });
                $('#channelMove').val(url);
              }
            </script>
            <%-- 存放 节目单地址 --%>
            <input value="" name="excelUrl"  id="channelMove" type="hidden"/>
            <%-- 存放 节目单json数据 --%>
            <div class="box-footer">
                <button class="btn btn-primary" type="submit"  onmouseover="SetChannel()"><s:message
                        code="save"/></button>
                <button class="btn btn-default" type="submit"  onclick="$('#redirect').val('list');"
                        onmouseover="SetChannel()"><s:message
                        code="saveAndReturn"/></button>
                <c:if test="${oprt=='create'}">
                    <button class="btn btn-default" type="submit"  onclick="$('#redirect').val('create');"
                            onmouseover="SetChannel()"><s:message
                            code="saveAndCreate"/></button>
                </c:if>
            </div>
        </form>
    </div>
</div>
</body>
</html>